﻿using System;
using System.Runtime.Serialization;

namespace IntoNails.Models
{
    [Serializable]
    public class ServicePriceException : AbstractModel<Guid>, ISerializable
    {
        #region Constructors

        protected ServicePriceException()
        {
        }

        public ServicePriceException(SerializationInfo info, StreamingContext context)
        {
            this.UniqueCode = (Guid) info.GetValue("UniqueCode", typeof (Guid));
            //this.DisplayName = info.GetString("DisplayName");
            this.AssociatedEmployee = (User) info.GetValue("AssociatedEmployee", typeof (User));
            this.AssociatedService = (Service) info.GetValue("AssociatedService", typeof (Service));
            this.Price = info.GetDouble("Minutes");
            this.CreatedDate = info.GetDateTime("CreatedDate");
            this.UpdatedDate = info.GetDateTime("UpdatedDate");
            this.IsValid = info.GetBoolean("IsValid");
        }

        #endregion

        #region Properties

        public User AssociatedEmployee { get; set; }
        public Service AssociatedService { get; set; }
        public double Price { get; set; }

        #endregion

        public static ServicePriceException CreateNewServicePriceException()
        {
            return new ServicePriceException();
        }

        public static ServicePriceException CreateServicePriceException(User associatedEmployee, Service associatedService, double price)
        {
            return new ServicePriceException
            {
                UniqueCode = Guid.NewGuid(),
                AssociatedEmployee = associatedEmployee,
                AssociatedService = associatedService,
                Price = price,
                CreatedDate = DateTime.Now,
                UpdatedDate = DateTime.Now,
                IsValid = true
            };
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("UniqueCode", this.UniqueCode);
            //info.AddValue("DisplayName", this.DisplayName);
            info.AddValue("AssociatedEmployee", this.AssociatedEmployee);
            info.AddValue("AssociatedService", this.AssociatedService);
            info.AddValue("Price", this.Price);
            info.AddValue("CreatedDate", this.CreatedDate);
            info.AddValue("UpdatedDate", this.UpdatedDate);
            info.AddValue("IsValid", this.IsValid);
        }
    }
}
